"""locale tricks, gettext initialization ETC"""
import platform
import codecs
import sys
import locale,gettext
if platform.system()=="Windows":
	import ctypes 
	ctypes.windll.kernel32.SetConsoleOutputCP(ctypes.windll.kernel32.GetACP())
	ctypes.windll.kernel32.SetConsoleCP(ctypes.windll.kernel32.GetACP())
	windowsLCID=ctypes.windll.kernel32.GetUserDefaultUILanguage()
	localeName=locale.windows_locale[windowsLCID]
	#sys.stdout = codecs.getwriter(locale.getpreferredencoding())(sys.stdout)
	sys.stderr = codecs.getwriter(locale.getpreferredencoding())(sys.stderr)
else:
	localeName=None
try: 
	if localeName:
		gettext.translation('loadstone', 'locale',languages=(localeName,)).install(True)
	else:
		gettext.translation('loadstone', 'locale').install(True)
except IOError:
	gettext.install("loadstone", unicode=True)
def initStdout():
	if platform.system()=="Windows":
		sys.stdout = codecs.getwriter(locale.getpreferredencoding())(sys.stdout)